package com.linxz.video.appui.lifebroadcast;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.linxz.framework.base.BaseMVPFragment;
import com.linxz.ui.GuiHelper;
import com.linxz.ui.widgets.LinxzRefreshLayout;
import com.linxz.video.R;
import com.linxz.video.adapter.LiveBroadCastAdapter;
import com.linxz.video.presenter.lifebroadcast.LifeBroadCastListPresenter;
/**
 * @author Linxz
 * 创建日期：2020年06月24日 07:57
 * version：v4.5.4
 * 描述：
 */
public class LifeBroadCastListFragment extends BaseMVPFragment<LifeBroadCastListPresenter> implements LifeBroadCastListView {

    private LinxzRefreshLayout layoutRefresh;
    private LiveBroadCastAdapter adapter;

    @Override
    protected LifeBroadCastListPresenter createPresenter() {
        return new LifeBroadCastListPresenter(this,lifecycleSubject);
    }

    @Override
    public Object setLayout() {
        return R.layout.ui_recycle_common;
    }

    @Override
    public void initUI() {
        layoutRefresh=findViewById(R.id.layoutRefresh);
        findViewById(R.id.layoutActionBar).setVisibility(View.GONE);
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        adapter=new LiveBroadCastAdapter(mvpPresenter.getLiveBroadCastData());
        GuiHelper.initRecycleView(activity, recyclerView,adapter,10);
        @SuppressLint("InflateParams") View headerDivider=LayoutInflater.from(activity).inflate(R.layout.ui_divider_1,null);
        adapter.addHeaderView(headerDivider);
    }

    @Override
    public void initData() {
        layoutRefresh.autoRefresh();
    }

    @Override
    public void setListener() {
        super.setListener();
        layoutRefresh.setOnRefreshListener(() -> mvpPresenter.refresh());
        layoutRefresh.setOnLoadMoreListener(refreshLayout -> mvpPresenter.loadMore());
        adapter.setOnLiveBroadCastItemClickListener(item -> {
            showToast("尼玛，该功能还未开通");
        });
    }

    @Override
    public void loadDataSuccess() {
        layoutRefresh.finishRefresh();
        layoutRefresh.finishLoadMore();
        adapter.notifyDataSetChanged();
    }

    @Override
    public void loadEmpty() {
        layoutRefresh.finishRefresh();
        layoutRefresh.finishLoadMore();
        @SuppressLint("InflateParams") View emptyView= LayoutInflater.from(activity).inflate(R.layout.ui_layout_empty,null);
        adapter.setEmptyView(emptyView);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void loadError() {
        layoutRefresh.finishRefresh();
        layoutRefresh.finishLoadMore();
        @SuppressLint("InflateParams") View errorView= LayoutInflater.from(activity).inflate(R.layout.ui_layout_error,null);
        adapter.setEmptyView(errorView);
        adapter.notifyDataSetChanged();
    }
}
